﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using gds_classes;

namespace gost_DigitalSignature
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("GOST Significator");
            Console.Write("Enter your message (number from 0 to {0} excluding): ",GOST_Signification.q);
            int message = int.Parse(Console.ReadLine());
            if (message <= 1 || message >= GOST_Signification.q)
            {
                Console.WriteLine("Invalid message");
                return;
            }
            Console.WriteLine();

            Random rnd = new Random();

            Console.Write("Enter your secret key: ");
            int x = int.Parse(Console.ReadLine());
            Console.WriteLine();

            int k = 0;
            int r = 0;
            int s = 0;

            while (s == 0 || r == 0)
            {
                k = rnd.Next(1, GOST_Signification.q);
                r = MathMethods.Mod((MathMethods.PowByMod(GOST_Signification.a, k, GOST_Signification.p)), GOST_Signification.q);
                s = MathMethods.Mod((k * GOST_Signification.Hash(message) + x * r), GOST_Signification.q);
            }
            Console.WriteLine("Significated message is: {0} , {1} , {2}", message, r, s);
            Console.ReadLine();
        }
    }
}
